#coding:utf-8
from django.db import models
from datetime import date
import datetime
#from django.contrib import admin
#class Question(models.Model):
#    question_text = models.CharField(max_length=200)
#    pub_date = models.DateTimeField('date published')
#    def __unicode__(self):
#        return self.question_text
#    def was_published_recently(self):
#        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
# Create your models here.


class Cabinet(models.Model):
    cabinet_lists = (
        ('A', 'A'),
        ('B', 'B'),
        ('C', 'C'),
        ('D', 'D'),
        ('E', 'E'),
        ('F', 'F'),
    )
    cabinet_list = models.CharField(u'机柜列',max_length=4, choices=cabinet_lists, default='A',null=True,blank=True)
    cabinet_number = models.CharField(u'机柜号',max_length=10, blank=True, null=True)
    cabinet_begin = models.CharField(u'起始U位',max_length=2, blank=True, null=True)
    class Meta:
        verbose_name = '机柜详情'
        verbose_name_plural = "机柜详情"
    def __unicode__(self):
        return self.cabinet_list

class Ip_details(models.Model):
    manager_ip = models.GenericIPAddressField(u'带外管理', max_length=20, blank=True, null=True, unique=True)
    manager_ip_netmask = models.GenericIPAddressField(u'带外掩码', max_length=20, blank=True, null=True)
    manager_ip_gateway = models.GenericIPAddressField(u'带外网关', max_length=20, blank=True, null=True)
    ip = models.GenericIPAddressField(u'业务IP', max_length=20, null=True,blank=True, unique=True)
    ip_netmask = models.GenericIPAddressField(u'业务掩码', max_length=20, blank=True, null=True)
    ip_gateway = models.GenericIPAddressField(u'业务网关', max_length=20, blank=True, null=True)
#    ip_details = models.ForeignKey('Server', verbose_name=u'IP详情', blank=True, null=True)
    class Meta:
        verbose_name = 'IP地址'
        verbose_name_plural = "IP地址"
    def __unicode__(self):
        return self.manager_ip

class Upload(models.Model):
    title = models.CharField(max_length=50)
    file = models.FileField(null=True,blank=True,upload_to='upload')
#    url_height = models.PositiveIntegerField(default=75)
#    url_width = models.PositiveIntegerField(default=75)
    img = models.ImageField(null=True,blank=True,upload_to="upload/img")

    def __unicode__(self):
        return self.title

class Supplier(models.Model):
    name =  models.CharField(u'供方', max_length=64, blank=True)
    bank = models.CharField(u'开户行', max_length=64, blank=True, null=True)
    bank_id = models.CharField(u'账号', max_length=64, blank=True, null=True)
    contact =  models.CharField(u'联系人', max_length=64, blank=True, null=True)
    phone = models.CharField(u'电话', max_length=64, blank=True, null=True)
    address = models.CharField(u'注册地址', max_length=64, blank=True, null=True)
    address2 = models.CharField(u'收货地址', max_length=64, blank=True, null=True)
    class Meta:
        verbose_name = '供方'
        verbose_name_plural = "供方"
    def __unicode__(self):
        return self.name

class Contract(models.Model):
    csn = models.CharField(u'合同号', max_length=128,unique=True)
    jiafang = models.CharField(u'甲方', max_length=128, unique=True)
    yifang = models.CharField(u'乙方', max_length=128, unique=True)

    cname = models.CharField(u'合同名称', max_length=64, null=True)
    producer = models.CharField(u'厂商', max_length=64, null=True)
    conf = models.ManyToManyField('Conf',  max_length=64, verbose_name=u'典配单', blank=True)
#    gongfang = models.CharField(u'供方', max_length=64, blank=True, null=True)
    price = models.FloatField(u'合同金额', null=True)
    detail = models.TextField(u'合同详细',blank=True, null=True)
    file = models.FileField(u'附件',null=True, blank=True, upload_to='upload/contract')
    contract_begin_date = models.DateField(u'合同生效日期', blank=True, null=True)
    contract_end_date = models.DateField(u'合同结束日期', blank=True, null=True)
    begin_date = models.DateField(u'保修开始日期', blank=True, null=True)
    end_date = models.DateField(u'保修结束日期', blank=True, null=True)

    class Meta:
        verbose_name = '合同'
        verbose_name_plural = "合同"
    def __unicode__(self):
        return self.cname

class Conf(models.Model):
    conf_types = (
        ('服务器', '服务器'),
        ('存储', '存储'),
        ('备件', '备件'),
    )

#    contract = models.ForeignKey('Contract', verbose_name=u'合同', blank=True)
    name =  models.CharField(u'ID', max_length=64,unique=True)
#    spare_details = models.ForeignKey('Spare_details', verbose_name=u'备件详情', blank=True)
    description =  models.CharField(u'描述', max_length=64)
   # conf_type =  models.CharField(u'配置类型', choices=conf_types, max_length=64, blank=True)
    price = models.FloatField(u'单价',blank=True, null=True)
    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
#    price_total = models.FloatField(u'总价',blank=True, null=True)


    class Meta:
        verbose_name = '典配单'
        verbose_name_plural = "典配单"
    def __unicode__(self):
        return self.name

class Board_card(models.Model):
    types = (
        ('type1', 'type1'),
        ('type2', 'type2'),
        ('type3', 'type3'),
    )
    board_type = models.CharField(u'板卡型号', max_length=64, choices=types, blank=True)
    pare_details = models.ForeignKey('Conf', verbose_name=u'备件详情', blank=True, null=True)
    #    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
    cpu_num = models.PositiveIntegerField(u'数量', blank=True, null=True)

    #    mem_create_time = models.DateTimeField(u'时间',blank=True, null=True)
    class Meta:
        verbose_name = 'Board_card'
        verbose_name_plural = 'Board_card'

    def __unicode__(self):
        return self.board_type

#####Disk_record#####
class Disk(models.Model):
    types = (
        ('SAS', 'SAS'),
        ('SATA', 'SATA'),
        ('SSD', 'SSD'),
        ('PCIE', 'PCIE'),
    )
    revs = (
        ('7.2k', '7.2k'),
        ('10k', '10k'),
        ('15k', '15k'),
        ('others', 'others'),
    )
    sizes = (
        ('400G', '400G'),
        ('480G', '480G'),
        ('600G', '600G'),
        ('900G', '900G'),
        ('1T', '1T'),
        ('1.2T', '1.2T'),
        ('1.5T', '1.5T'),
        ('1.8T', '1.8T'),
        ('2T', '2T'),
        ('3.2T', '3.2T'),
        ('4T', '4T'),
        ('6.4T', '6.4T'),
    )

    pare_details = models.ForeignKey('Conf', verbose_name=u'备件详情', blank=True, null=True)
    disk_type = models.CharField(u'硬盘类型',max_length = 64, choices=types,blank=True, null=True)
    disk_rev = models.CharField(u'硬盘转速',max_length = 64, choices=revs,blank=True, null=True)
    disk_size = models.CharField(u'磁盘容量',max_length = 12, choices=sizes,blank=True, null=True)
#    disk_product = models.CharField(u'厂商',max_length = 64, choices=products,blank=True, null=True)
#    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
    disk_num = models.PositiveIntegerField(u'数量',blank=True, null=True)
#    create_time = models.DateTimeField(u'时间',blank=True, null=True)
    class Meta:
        verbose_name = '硬盘'
        verbose_name_plural = '硬盘'
    def __unicode__(self):
        return self.disk_size

class Cpu(models.Model):
    types = (
        ('E5-2609v3', 'E5-2609v3'),
        ('E5-2620v3', 'E5-2620v3'),
        ('E5-2630v3', 'E5-2630v3'),
        ('E5-2640v3', 'E5-2640v3'),
    )
    cpu_type = models.CharField(u'CPU型号', max_length=64, choices=types, blank=True)
    pare_details = models.ForeignKey('Conf', verbose_name=u'备件详情', blank=True, null=True)
    cpu_core = models.IntegerField(u'线程数量', blank=True, null=True)
#    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
    cpu_num = models.PositiveIntegerField(u'数量',blank=True, null=True)
#    mem_create_time = models.DateTimeField(u'时间',blank=True, null=True)
    class Meta:
        verbose_name = 'CPU'
        verbose_name_plural = 'CPU'
    def __unicode__(self):
        return self.cpu_type

#####Memery_record#####
class Memery(models.Model):
    mem_types = (
        ('ddr4', 'ddr4'),
    )
    mem_sizes = (
        ('8G', '8G'),
        ('16G', '16G'),
        ('32G', '32G'),
    )
    pare_details = models.ForeignKey('Conf', verbose_name=u'备件详情', blank=True, null=True)
    mem_type = models.CharField(u'内存类型',max_length = 64, choices=mem_types,blank=True, null=True)
    mem_size = models.CharField(u'内存容量',max_length = 12, choices=mem_sizes,blank=True, null=True)
#    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
    mem_num = models.PositiveIntegerField(u'数量',blank=True, null=True)
#    mem_create_time = models.DateTimeField(u'时间',blank=True, null=True)
    class Meta:
        verbose_name = '内存'
        verbose_name_plural = '内存'
    def __unicode__(self):
        return self.mem_size


#####network_card_record#####
class Nic(models.Model):
    speeds = (
        ('1000Mbps/s', '1000Mbps/s'),
        ('10000Mbps/s', '10000Mbps/s'),
    )
    nic_types = (
        (u'光口', u'光口'),
        (u'电口', u'电口'),
    )
    pcis = (
        (u'PCI-长', u'PCI-长'),
        (u'PCI-短', u'PCI-短'),
    )
    pare_details = models.ForeignKey('Conf', verbose_name=u'备件详情', blank=True, null=True)
    nic_speed = models.CharField(u'网卡速率',max_length = 64, choices=speeds, blank=True, null=True)
    nic_type = models.CharField(u'网卡类型',max_length = 12, choices=nic_types, blank=True, null=True)
    nic_pci = models.CharField(u'PCI卡类型',max_length = 12, choices=pcis,blank=True, null=True)
#    supplier = models.ForeignKey('Supplier', verbose_name=u'供方', blank=True)
    nic_num = models.PositiveIntegerField(u'数量',blank=True, null=True)
#    nic_create_time = models.DateTimeField(u'时间',blank=True, null=True)
    class Meta:
        verbose_name = '网卡'
        verbose_name_plural = '网卡'
    def __unicode__(self):
        return self.nic_type

class Menber(models.Model):
    name = models.CharField(u'姓名',max_length = 30, blank=True)
    phone = models.CharField(u'电话',max_length = 30, blank=True)
    email = models.EmailField(u'Email',max_length = 64, blank=True)
    class Meta:
        verbose_name = '成员'
        verbose_name_plural = '成员'
    def __unicode__(self):
        return self.name
#    def __str__(self):
#        return "<%s>" % self.name

class Ticket(models.Model):
    menbers = (
        (u'苏建', u'苏建'),
        (u'陈桥', u'陈桥'),
        (u'徐松', u'徐松'),
        (u'吴磊', u'吴磊'),
        (u'沈阳', u'沈阳'),
        (u'李君', u'李君'),
        (u'吴祖兵', u'吴祖兵'),
    )

    ticket_sources = (
        (u'报修跟进', u'报修跟进'),
        (u'客服传达', u'客服传达'),
        (u'上级安排', u'上级安排'),
        (u'客户对接', u'客户对接'),
    )

    ticket_types = (
        (u'定时巡检', u'定时巡检(工单)'),
        (u'设备迁移', u'设备迁移(变更)'),
        (u'系统配置', u'系统配置(变更)'),
        (u'设备维修', u'设备维修(变更)'),
        (u'设备上架', u'设备上架(变更)'),
        (u'设备下架', u'设备下架(变更)'),
        (u'协助处理', u'协助处理(工单)'),
        (u'系统安装', u'系统安装(工单)'),
        (u'增加备件', u'增加备件(变更)'),
        (u'移除备件', u'移除备件(变更)'),
        (u'技术研究', u'技术研究'),
    )
    ticket_groups = (
        (u'系统组', u'系统组'),
        (u'网络组', u'网络组'),
    )
    ticket_status = (
        (u'处理中', u'处理中'),
        (u'已完成', u'已完成'),
    )
    ticket_content = models.CharField(u'内容描述', max_length=300, default='注:所有变更单需提交DCIM系统;', blank=True, null=True)
    ticket_group = models.CharField(u'工单分组', max_length=30, choices=ticket_groups, blank=True, default='系统组')
    ticket_source = models.CharField(u'工单来源', max_length=30, choices=ticket_sources, blank=True, null=True)
    ticket_time = models.DateTimeField(u'开始时间', blank=True, null=True)
    ticket_type = models.CharField(u'工单类型', max_length=30, choices=ticket_types, blank=True,
                                   null=True)
    ticket_id = models.CharField(u'变更单号',  max_length=30, blank=True, default='若为变更单，请>输入DCIM上的变更单号')
    related_servers = models.CharField(u'涉及设备SN', default='多台请用空格隔开',max_length=300, blank=True, null=True)
    server_number = models.IntegerField(u'涉及设备数量', blank=True, default=0)
    #    ticket_state = models.CharField(u'工单状态',max_length = 30, choices=ticket_status, blank=True, null=True, default='处理中')
    #    menber = models.CharField(u'处理人',max_length=64, blank=True, null=True)
    #    menber = models.ManyToManyField('Menber' , blank=True)
    executor = models.CharField(u'执行人', max_length=30, choices=menbers, blank=True)
    menber = models.ManyToManyField('Menber', verbose_name=u'协助处理人', blank=True)
    ticket_state = models.BooleanField(u'是否完成', default=False, )
    end_time = models.DateTimeField(u'完成时间', blank=True, null=True)
    remark = models.TextField(u'备注', blank=True, null=True)

    def get_menber(self):
        return "\n".join([m.name for m in self.menber.all()])

    class Meta:
        verbose_name = '工单记录'
        verbose_name_plural = '工单记录'
    def __unicode__(self):
        return self.ticket_content
class Ivn_server(models.Model):
    server_ress = (
        (u'出库', u'出库'),
        (u'入库', u'入库'),
    )
    sn = models.CharField(u'资产SN号',max_length=20,blank=True, null=True, unique=True)
    brand = models.CharField(u'品牌',max_length=20,blank=True)
    types = models.CharField(u'典配类型',max_length=20,blank=True)
    contract = models.ForeignKey('Contract', verbose_name=u'合同', null=True, blank=True)
    change_times = models.DateTimeField(u'出/入库时间')
    change_stat = models.CharField(u'出/入库记录', choices=server_ress, max_length=32, blank=True, null=True)
    rec_person = models.CharField(u'记录人',max_length=64, blank=True)
    change_num = models.IntegerField(u'出/入数量', blank=True, null=True)
    ivn_num = models.IntegerField(u'库存数量', blank=True, null=True)
    remarks = models.CharField(u'备注',max_length=200, blank=True, null=True, default='None')

    class Meta:
        verbose_name = '服务器库存'
        verbose_name_plural = '服务器库存'

    def __unicode__(self):
        return self.sn

class Server(models.Model):
    statuss = (
        ( u'使用中', u'使用中'),
        ( u'待维修', u'待维修'),
        ( u'维修中', u'维修中'),
        ( u'入库', u'入库'),
    )
    physical = (
        (u'物理机', u'物理机'),
        (u'虚拟机',  u'虚拟机'),
    )
    model_numbers = (
        ('Mod1', 'Mod1'),
        ('Mod2', 'Mod2'),
        ('Mod3', 'Mod3'),
        ('Mod4', 'Mod4'),
        ('Ecc', u'Ecc'),
    )
    os_types = (
        ('Windows', 'Windows'),
        ('CentOS', 'CentOS'),
        ('RedHat', 'RedHat'),
        ('Esxi', 'Esxi'),
        ('Others', 'Others'),
    )

    cabinet_numbers = (
         ('1', '1'),
         ('2', '2'),
         ('3', '3'),
         ('4', '4'),
     )
    sn = models.CharField(u'资产SN号',max_length=20,blank=True, null=True, unique=True)
    cabinet = models.ForeignKey('Cabinet', verbose_name=u'机柜详情', null=True, blank=True)
    contract = models.ForeignKey('Contract', verbose_name=u'合同', null=True, blank=True)
    conf = models.ForeignKey('Conf', verbose_name=u'典配信息', null=True, blank=True)
    ip_details = models.ForeignKey('Ip_details', verbose_name=u'IP详情', null=True, blank=True)
    idc_mod = models.CharField(u'模块机房',max_length=10, choices=model_numbers,default='Mod2',  blank=True, null=True)
    password = models.CharField(u'密码',max_length=64,null=True,blank=True)
    hostname = models.CharField(u'主机名',max_length=30, null=True,blank=True)
    check = models.BooleanField(u'是否监控',default=True)
#    health = models.BooleanField(u'健康状态',default=True)
#    cabinet_end = models.CharField(u'结束U位',max_length=2, blank=True, null=True)

    status = models.CharField(u'服务器状态',max_length=64, choices=statuss, default='enable', blank=True, null=True)
    os = models.CharField(u'操作系统',max_length=30,choices=os_types, blank=True, null=True)
    release = models.CharField(u'版本号',max_length=20, blank=True, null=True)
    owner  = models.CharField(u'接口人',max_length=128, blank=True, null=True)
#    onsale = models.DateField(("Date"), default=date.today)
    create_date = models.DateField(u'上架时间', default=date.today, blank=True, null=True)
    update_date = models.DateTimeField(u'检查时间',blank=True, auto_now=True, null=True)
    machine_type = models.CharField(u'机器类型',max_length=20, choices=physical, default='physical', blank=True, null=True)
    department = models.CharField(u'部门',max_length=128, blank=True, null=True)
    business = models.CharField(u'业务',max_length=50, blank=True, null=True, default='None')
    remarks = models.CharField(u'备注',max_length=200, blank=True, null=True, default='None')

    class Meta:
        verbose_name = '服务器'
        verbose_name_plural = '服务器'
    def __unicode__(self):
        return self.sn

class HostGroup(models.Model):
    name = models.CharField(max_length=30)
    members = models.ManyToManyField(Server)
    class Meta:
        verbose_name = '服务器分组'
        verbose_name_plural = '服务器分组'
    def __unicode__(self):
        return self.name

#class Choice(models.Model):
#    question = models.ForeignKey(Server)
#    choice_text = models.CharField(max_length=200)
#    votes = models.IntegerField(default=0)
#    def __unicode__(self):
#        return self.choice_text

class Record(models.Model):
    statuss = (
        ('A', u'已报修，等待厂商派单'),
        ('G', u'已派单，缺配件'),
        ('B', u'确认交付人'),
        ('C', u'确认停机维护时间'),
        ('D', u'暂时不能停机'),
        ('E', u'维修后，故障依然存在'),
        ('F', u'完成，故障解除'),
    )
    fault_types = (
        (u'硬盘', u'硬盘'),
        (u'内存', u'内存'),
        (u'阵列卡', u'阵列卡'),
        (u'主板', u'主板'),
        (u'电源', u'电源'),
        (u'其他', u'其他'),
    )
    reports = (
        (u'苏建', u'苏建'),
        (u'陈桥', u'陈桥'),
        (u'徐松', u'徐松'),
        (u'吴磊', u'吴磊'),
        (u'沈阳', u'沈阳'),
        (u'李君', u'李君'),
        (u'吴祖兵', u'吴祖兵'),
    )
    ress = (
        (u'成功', u'成功'),
        (u'失败', u'失败'),
    )
    server = models.ForeignKey(Server)
#    fault_descrip = models.CharField(u'故障描述',max_length=120, blank=True, null=True,)
    fault_type = models.CharField(u'故障类型',max_length=64, choices=fault_types, blank=True, null=True, default='')
    state = models.CharField(u'处理状态',max_length=64, choices=statuss, blank=True, null=True, default='')
    discover_time = models.DateTimeField(u'发现故障时间', blank=True,null=True)
    report_time = models.DateTimeField(u'报修时间',blank=True,null=True)
    report_person = models.CharField(u'报修人',max_length=64, choices=reports, blank=True, null=True)
    end_time = models.DateTimeField(u'处理故障时间',blank=True,null=True)
    repair_person = models.CharField(u'处理人',max_length=64, choices=reports, blank=True, null=True)
    res = models.CharField(u'处理结果', choices=ress, max_length=6, blank=True, null=True)
    memo = models.CharField(u'结果备注',max_length=120, blank=True, null=True)
    class Meta:
        verbose_name = '维修记录'
        verbose_name_plural = '维修记录'
    def __unicode__(self):
        return self.state

###########
class Disk_rec(models.Model):
    recs = (
        (u'苏建', u'苏建'),
        (u'陈桥', u'陈桥'),
        (u'徐松', u'徐松'),
        (u'吴磊', u'吴磊'),
        (u'沈阳', u'沈阳'),
        (u'李君', u'李君'),
        (u'吴祖兵', u'吴祖兵'),
    )
    disk_ress = (
        (u'出库', u'出库'),
        (u'入库', u'入库'),
    )
    server = models.ForeignKey(Disk)
    change_time = models.DateTimeField(u'出/入库时间', blank=True,null=True)
    change_stat = models.CharField(u'出/入库记录', choices=disk_ress, max_length=32, blank=True, null=True)
    related_servers = models.CharField(u'关联设备(多台请用","隔开)',max_length = 300, blank=True, null=True)
    rec_person = models.CharField(u'记录人',max_length=64, choices=recs, blank=True, null=True)
    disk_change = models.IntegerField(u'出/入数量', blank=True, null=True)
    disk_num = models.PositiveIntegerField(u'现有库存', blank=True, null=True)
    memo = models.CharField(u'结果备注',max_length=120, blank=True, null=True)
    class Meta:
        verbose_name = '硬盘库存记录'
        verbose_name_plural = '硬盘库存记录'
    def __unicode__(self):
        return self.disk_num

###########
class Memery_rec(models.Model):
    recs = (
        (u'苏建', u'苏建'),
        (u'陈桥', u'陈桥'),
        (u'徐松', u'徐松'),
        (u'吴磊', u'吴磊'),
        (u'沈阳', u'沈阳'),
        (u'李君', u'李君'),
        (u'吴祖兵', u'吴祖兵'),
    )
    memrecs = (
        (u'出库', u'出库'),
        (u'入库', u'入库'),
    )
    server = models.ForeignKey(Memery)
    change_time = models.DateTimeField(u'出/入库时间', blank=True,null=True)
    change_stat = models.CharField(u'出/入库记录', choices=memrecs, max_length=32, blank=True, null=True)
    related_servers = models.CharField(u'关联设备(多台请用","隔开)',max_length = 300, blank=True, null=True)
    rec_person = models.CharField(u'记录人',max_length=64, choices=recs, blank=True, null=True)
    memery_change = models.IntegerField(u'出/入数量', blank=True, null=True)
    memery_num = models.PositiveIntegerField(u'现有库存', blank=True, null=True)
    memo = models.CharField(u'结果备注',max_length=120, blank=True, null=True)
    class Meta:
        verbose_name = '内存库存记录'
        verbose_name_plural = '内存库存记录'
    def __unicode__(self):
        return self.memery_num

###########
class Nic_rec(models.Model):
    recs = (
        (u'苏建', u'苏建'),
        (u'陈桥', u'陈桥'),
        (u'徐松', u'徐松'),
        (u'吴磊', u'吴磊'),
        (u'沈阳', u'沈阳'),
        (u'李君', u'李君'),
        (u'吴祖兵', u'吴祖兵'),
    )
    nic_ress = (
        (u'出库', u'出库'),
        (u'入库', u'入库'),
    )
    server = models.ForeignKey(Nic)
#    fault_descrip = models.CharField(u'故障描述',max_length=120, blank=True, null=True,)
    change_time = models.DateTimeField(u'出/入库时间', blank=True,null=True)
    change_stat = models.CharField(u'出/入库记录', choices=nic_ress, max_length=32, blank=True, null=True)
    related_servers = models.CharField(u'关联设备(多台请用","隔开)',max_length = 300, blank=True, null=True)
    rec_person = models.CharField(u'记录人',max_length=64, choices=recs, blank=True, null=True)
    nic_change = models.IntegerField(u'出/入数量', blank=True, null=True)
    nic_num = models.PositiveIntegerField(u'现有库存', blank=True, null=True)
    memo = models.CharField(u'备注',max_length=120, blank=True, null=True)
    class Meta:
        verbose_name = '网卡库存记录'
        verbose_name_plural = '网卡库存记录'
    def __unicode__(self):
        return unicode(self.nic_num)
class Blogs(models.Model):
    reports = (
            (u'苏建', u'苏建'),
            (u'陈桥', u'陈桥'),
            (u'徐松', u'徐松'),
            (u'吴磊', u'吴磊'),
            (u'沈阳', u'沈阳'),
            (u'李君', u'李君'),
            (u'吴祖兵', u'吴祖兵'),
    )
    title = models.CharField(u'标题', max_length=150)
    body = models.TextField(u'正文')
#    ctime = models.DateTimeField(u'时间')
    author = models.ManyToManyField('Menber', blank=True)
    file = models.FileField(u'附件',null=True, blank=True, upload_to='upload/files')
    img = models.ImageField(u'图片',null=True, blank=True, upload_to="upload/imgs")
    ctime = models.DateTimeField(auto_now=True)         #自动添加创建时间
#    uptime = models.DateTimeField(auto_now_add=True)    #自动添加更新时间
    def get_author(self):
        return "\n".join([m.name for m in self.author.all()])

    class Meta:
        verbose_name = 'blogs'
        verbose_name_plural = 'blogs'

    def __unicode__(self):
        return self.title

class Conf_record(models.Model):
    parts_types = (
        (u'硬盘', u'硬盘'),
        (u'内存', u'内存'),
        (u'网卡', u'网卡'),
        (u'SSD卡', u'SSD卡'),
    )
    actions = (
        (u'增加', u'增加'),
        (u'移除', u'移除'),
    )

    server = models.ForeignKey(Server)
    #    fault_descrip = models.CharField(u'故障描述',max_length=120, blank=True, null=True,)
    type = models.CharField(u'备件类型', max_length=64, choices=parts_types, blank=True, null=True, default='')
    memo = models.CharField(u'备件描述(容量/型号)', max_length=120, blank=True, null=True)
    state = models.CharField(u'增减情况', max_length=64, choices=actions, blank=True, null=True, default='')
    parts_num = models.PositiveIntegerField(u'数量', blank=True, null=True)
    executor = models.ForeignKey('Menber', verbose_name=u'操作人', blank=True)
    change_time = models.DateTimeField(u'变更时间', blank=True, null=True)

    class Meta:
        verbose_name = '备件变更记录'
        verbose_name_plural = '备件变更记录'

    def __unicode__(self):
        return self.type
#class Connect(models.Model):
#    server = models.ForeignKey(Server, null=True)
#    memo = models.TextField(u'备注', blank=True, null=True)
